﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace MSAS.DIP.Common
{
    /// <summary>
    /// Class that defines the parameters for retry schemes and also reads
    /// static values from config.
    /// </summary>
    public class RetryWait
    {
        #region Serialization Properties

        [XmlAttribute(AttributeName="InitialWaitTime", DataType="duration")]
        public string InitialWaitTimeString
        {
            get
            {
                return InitialWaitTime.ToString();
            }
            set
            {
                InitialWaitTime = TimeSpan.Parse(value);
            }
        }

        [XmlAttribute(AttributeName = "TotalWaitTime", DataType = "duration")]
        public string TotalWaitTimeString
        {
            get
            {
                return TotalWaitTime.ToString();
            }
            set
            {
                TotalWaitTime = TimeSpan.Parse(value);
            }
        }

        #endregion

        [XmlAttribute]
        public double WaitScalingFactor { get; set; }

        #region Unserializable Properties

        [XmlIgnore]
        public TimeSpan InitialWaitTime { get; set; }
        [XmlIgnore]
        public TimeSpan TotalWaitTime { get; set; }

        #endregion

        /// <summary>
        /// ShortWait as defined in the App.config
        /// </summary>
        public static readonly RetryWait ShortWait = Properties.Settings.Default.ShortRetryWait;
    }
}
